package homework.Day0322;

import java.util.Scanner;

public class VendingMachine {
    public static void main(String[] args) {

        int[] arr = {9,9,9,9,9};

        Scanner in = new Scanner(System.in);

        while (true) {
            System.out.printf(
                            "*---------------------------*\n" +
                            "|     Vending   Machine     |\n" +
                            "*---------------------------*\n" +
                            "|   A    B    C    D    E   |\n" +
                            "|  [%d]  [%d]  [%d]  [%d]  [%d]  |\n" +
                            "*---------------------------*\n" +
                            "请输入购买的商品(A~E):\n" +
                            "1. A\n" +
                            "2. B\n" +
                            "3. C\n" +
                            "4. D\n" +
                            "5. E\n" +
                            "0. 退出",arr[0],arr[1],arr[2],arr[3],arr[4]);
            System.out.println();

            System.out.print("你的输入：");

            String input = in.nextLine();

            try {
                int unm = Integer.parseInt(input);
                switch (unm) {
                    case 0:
                        System.out.println("谢谢惠顾！");
                        System.exit(0);
                    case 1:
                    case 2:
                    case 3:
                    case 4:
                    case 5:
                        if (arr[unm - 1] > 0){
                            arr[unm - 1] = arr[unm - 1] - 1;
                        }else {
                            System.out.println("今日已售罄");
                        }
                        break;
                    default:
                        System.out.println("输入不合法");
                }
            } catch (NumberFormatException e) {
                System.out.println("输入不合法");
            }
        }
    }

}
